
<template>
	<view :style="`height: calc(${navTop||0}px + 88rpx)`" v-if="show||showClone">
		<view :class="'headTop ' + grayscale"
			:style="'padding-top:' + navTop + 'px; background-color:' + headerBg + '; '">
			<view class="headBgBox headBg" :style="'padding-top:' + navTop + 'px; opacity:' + (headerBgImg ? 1 : 0)">
				<image :src="imgPath + '/' + module + '/bg_index.png?v=' + imgVersion" mode="widthFix" class="headBgImg img" v-if="module != 'siteConfig' && headerBgImg"></image>
			</view>
			
			<view class="head" :style="'margin-top:' + offTop + 'px'">
				<!-- 大首页头部 -->
				<block v-if="module == 'siteConfig'">
					<view class="headCon" :style="`width:${navLeft}`">
						<view class="city index" v-if="cityNum > 1" data-url="/pages/changeCity/index?module=siteConfig"
							@tap="goLink" data-type="1">
							<text>{{ cityInfoClone.name }}</text>
							<image class="arr" :src="imgPath + '/info/arr_down.png?v=' + imgVersion" mode="widthFix" />
						</view>
						<view class="searchInp">
							<view class="searchIcon">
								<image :src="imgPath + '/skin1/search_icon.png?v=' + imgVersion" mode="aspectFit">
								</image>
							</view>
							<view class="swiperBox">
								<swiper class="searchSwipe search" interval="2000" :circular="true"
									:autoplay="searchHot.length > 0" :vertical="true">
									<block v-if="searchHot.length > 0" v-for="(item, index) in searchHot" :key="index">
										<swiper-item :data-keys="item.oldkeyword"
											@touchmove.stop.prevent="catchTouchMove" @tap="toSearchPage" data-url=""
											data-type="2">
											<view class="searchInp">{{ item.oldkeyword }}</view>
										</swiper-item>
									</block>
									<block v-if="searchHot.length == 0">
										<swiper-item @tap="toSearchPage" data-url="" class="swiperItem">
											<view class="searchInp">搜索</view>
										</swiper-item>
									</block>
								</swiper>
							</view>
						</view>
						<view class="scanIcon" @tap="scanQr">
							<image :src="imgPath + '/skin1/scanIcon.png?v=' + imgVersion" mode="aspectFit">
							</image>
						</view>
					</view>
				</block>
				<!-- 外卖头部 -->
				<block v-else-if="module == 'waimai' && !backOnly">
					<view class="leftCon">
						<view class="backBtn" @tap="goback">
							<image class="img" :src="imgPath + '/waimai/header_back_index.png?v=' + imgVersion"></image>
						</view>
						<text class="text">{{ headerTitle }}</text>
						<view class="posi">
							<view class="posiIcon">
								<image class="img" :src="imgPath + '/waimai/posi.png?v=' + imgVersion" mode="aspectFill">
								</image>
							</view>
							<view class="posiText" data-url="/pages/packages/waimai/local/local" data-type="1"
								@tap="goLink">
								{{ posiInfo && posiInfo.address ? posiInfo.address : '定位中...' }}
							</view>
							<view class="arr_r">
								<image class="img" :src="imgPath + '/waimai/arr_r.png?v=' + imgVersion" mode="aspectFill">
								</image>
							</view>
						</view>
					</view>
				</block>

				<!-- 招聘首页 -->
				<block v-else-if="module == 'job' ">
					<view class="headerCon" >
						<view class="leftCon"  @tap="gobackFn">
							<view  :class="'headBtns ' + (!headerBack || backOnly ? 'circle' : '') + ' ' + (noBorder ? 'noCircle' : '')" v-if="!ifIndex || !headerBack">
							<!-- 返回 -->
								<view class="navBack navbtn" >
									<image class="navbtnImg img" :src="imgPath + '/info/navBack.png?v=' + imgVersion" mode="aspectFill" v-if="!backDefine"></image>
									<image class="navbtnImg img" :src="backDefine" mode="aspectFill" v-else></image>
								</view>
							</view>
							<view class="headerTitle" >
								<slot name="headTitle"></slot>
							</view>
						</view>
						<view class="rightBtns" :style="rightGrow ? 'flex-grow:1;min-width:0;' : ''">
							<slot name="rightbtns"></slot>
						</view>
					</view>
				</block>

				<!-- 通用头部 -->
				<block v-else>
					<view
						:class="'headBtns ' + (!headerBack || backOnly ? 'circle' : '') + ' ' + (noBorder ? 'noCircle' : '')"
						v-if="!ifIndex || !headerBack">
						<!-- 返回 -->
						<view class="navBack navbtn" @tap="goback" v-if="!(!headerBack || homeBackClone)">
							<image class="navbtnImg img" :src="imgPath + '/info/navBack.png?v=' + imgVersion"
								mode="aspectFill"></image>
						</view>

						<view class="navBack navbtn" @tap="homeBackFun" v-if="!(!homeBackClone || !headerBack)">
							<image class="navbtnImg img" :src="imgPath + '/info/homepage.png?v=' + imgVersion"
								mode="aspectFill"></image>
						</view>

						<view class="navBack navbtn" @tap="backIndex" v-if="!headerBack">
							<image class="navbtnImg img" :src="imgPath + '/info/navBack.png?v=' + imgVersion"
								mode="aspectFill"></image>
						</view>

						<view class="navLine"></view>
						<!-- 菜单 -->
						<view class="navMenu navbtn" @tap="showMenu">
							<image :src="imgPath + '/info/menu_icon.png?v=' + imgVersion" mode="aspectFill"
								class="navbtnImg" />
							<view class="bg_mask" v-if="headMenuShow" @touchstart.stop.prevent="hideMenu"></view>
							<view class="navMenuBox" v-if="headMenuShow">
								<view class="arr_top">
									<image :src="imgPath + '/info/arr_top.png?v=' + imgVersion" mode="aspectFill"
										class="topImg" />
								</view>
								<block v-for="(item, index) in navList" :key="index">
									<view class="navMenuLi" :data-url="item.url" @tap="goLink" :data-type="item.type">
										<image :src="imgPath + '/info/' + item.icon + '?v=' + imgVersion"
											mode="aspectFill" class="navImg" />
										<view class="navText">
											{{ item.title }}
											<view class="circle_txt" v-if="item.msg && msgNum > 0">
												{{ msgNum }}
											</view>
										</view>
									</view>
								</block>
							</view>
						</view>
					</view>
					<view class="city" v-else-if="ifIndex && cityNum > 1"
						:data-url="'/pages/changeCity/index?module=' + module" @tap="goLink" data-type="3">
						<text>{{ cityInfoClone.name }}</text>
						<image class="arr img" :src="imgPath + '/info/arr_down.png?v=' + imgVersion" mode="widthFix" />
					</view>
					<text class="text">{{ headerTitle }}</text>
				</block>
				<!-- 右侧占位（只在微信端起作用） -->
				<view class="navPlace" v-if="showClone" :style="navWidth ? ('width:'+(navWidth)+'px;height:2rpx;opciaty:0; ') : ''"></view>
			</view>
		</view>
		<view class="pullDownRefresh" :style="'top:' + navTop + 'px'">
			<view class="icon" v-if="!pullend">
				<image :src="imgPath + '/info/pullDown.png?v=' + imgVersion"></image>
			</view>
			<view class="icon rotate" v-else-if="!pullend">
				<image :src="imgPath + '/info/refresh.png?v=' + imgVersion"></image>
			</view>
			<view class="pullState">{{ pullend ? '正在刷新' : '松开刷新' }}</view>
		</view>

		<!-- 底部导航栏 -->
		<bottom-nav :module="module" active="0" v-if="showBottom" :msgNum="msgNum" :needMessage="false"></bottom-nav>
	</view>
</template>

<script>
	// 平台兼容说明：
	// 1.showClone为平台兼容显/隐控制，抖音默认为false，微信默认为true
	// 2.show为手动控制显/隐，默认值是false（有些抖音需要头部）
	// 3.show与showClone的关系为“或”
	import bottomNav from '../bottom_nav/bottom_nav';
	// pages/components/public_headerr.js
	const app = getApp();
	import refreshToken from '../../utils/refreshToken.js'
	let getMessageInterval = null;
	export default {
		components: {
			bottomNav
		},
		data() {
			return {
				globalData:app.globalData,
				navTop: app.globalData.navTop,
				menuTop: 0,

				//胶囊距离顶部
				navLeft: 0,

				offTop: 0,
				imgVersion: app.globalData.imgVersion,

				//图片版本号
				imgPath: app.globalData.imgPath,

				//图片版本号
				headMenuShow: false,

				//显示菜单
				msgNum: 0,

				cityurl: '/pages/redirect/index?url=' +
					app.globalData.masterDomain +
					'/changecity.htmlhuoniaowhcurrentPageOpenhuoniaodh1huoniaoljbackModulehuoniaodhinfohuoniaoljfromOriginalhuoniaodh1',
				grayscale: app.globalData.appConfig.sitePageGray == '1' || app.globalData.appConfig.sitePageGray == '2' ?
					'grayscale' : '',
				lng: '',
				lat: '',
				cityNum: '',
				navList: [],
				msgNumClone: 0,

				cityInfoClone: {
					name: ''
				},

				homeBackClone: false,
				showClone: false,
				navWidth:0, //胶囊宽度
				// 兼容项
				platForm: app.globalData.platForm,
				click_disabled:false,  //避免点击事件触发多次
				timerHead:null, //消息接口定时器
				// web_wxmini:false, //h5_ 在小程序中显示
			};
		},
		/**
		 * 组件的属性列表
		 */
		props: {
			ifIndex: {
				//是否为大首页
				type: Boolean,
				default: false
			},
			headerTitle: {
				//标题
				type: String,
				default: '分类信息'
			},
			headerBgImg: {
				//背景图
				type: Boolean,
				default: false
			},
			headerBgOpacity: {
				//背景图
				type: String,
				default: '1'
			},
			headerBg: {
				//背景图
				type: String,
				default: '#fff'
			},
			headerBack: {
				//返回上一页
				type: Boolean,
				default: true
			},
			homeBack: {
				//home按钮
				type: Boolean,
				default: false
			},
			pullend: {
				//下拉结束
				type: Boolean,
				default: false
			},
			backOnly: {
				//是否是圆形按钮
				type: Boolean,
				default: false
			},
			noBorder: {
				//有无边框
				type: Boolean,
				default: false
			},
			
			module: {
				//模块名，底部按钮用的
				type: String,
				default: 'info'
			},
			activeIndex: {
				type: Number,
				default: 0
			},
			showBottom: {
				//是否显示底部
				type: Boolean,
				default: false
			},
			cityInfo: {
				//城市
				type: Object,
				default: {
					name: app.globalData.cityInfo.name ? app.globalData.cityInfo.name : '加载中',
					cityid: app.globalData.cityInfo.cityid
				}
			},
			//定位城市

			posiInfo: {
				type: Object,
				default: {
					address: '定位中'
				}
			},
			// skin2新增
			scanIcon: {
				type: Boolean,
				default: false
			},
			// 模板
			temp: {
				type: String,
				default: ' '
			},
			// 搜索框
			searchInp: {
				type: Boolean,
				default: false
			},
			searchHot: {
				type: Array,
				default: []
			},
			needMessage: { //是否需要获取消息信息
				type: Boolean,
				default: false
			},
			pageHide: { //needMessage为true时，必传
				type: Boolean,
				default: false
			},
			show: { //该组件的显隐
				type: Boolean,
				default: false
			},

			// 右侧按钮 是否长度自适应
			rightGrow:{
				type:Boolean,
				default:false
			},

			backDefine:{
				type:String,
				default:'', //是否使用自定义返回按钮
			}
		},
		mounted() {
			// 平台切换：微信自定义头部
			if (app.globalData.platForm == 'mp-weixin') {
				this.wexin();
				this.$nextTick(res => {
					this.attached();
				})
			} else if (app.globalData.platForm == 'mp-toutiao') {
				this.toutiao();
			}else if(app.globalData.platForm == 'web'){ //微信小程序 显示web
				// let that = this;
				// if(navigator.userAgent.toLowerCase().match(/micromessenger/)){
				// 	jWeixin.miniProgram.getEnv(function (res) {
				// 		let wx_miniprogram = res.miniprogram;

				// 		window.wx_miniprogram_judge = true;
				// 		if (wx_miniprogram) {
				// 			that.web_wxmini = true
				// 		} else {
				// 			that.web_wxmini = false
				// 		}
				// 	});
				// }else{
				// 	that.web_wxmini = false
				// }
			}
			this.handlePageShow();
			// app.watch(this.pageChangeVisible,'pageVisible') undefined报错
		},
		unmounted() {
			clearInterval(this.timerHead);
		},
		/**
		 * 组件的方法列表
		 */
		methods: {
			// 页面切换至前后台之后触发
			pageChangeVisible(val){
				const that = this
				if(val){ //表示显示在前台
					if(that.needMessage && Boolean(app.globalData.userid)){
						this.timerHead = setInterval(res => {
							this.getMessage();
						}, 5000)
						this.pageShowCheck(5)
					}
				}else{ //表示切换至后台
					clearInterval(this.timerHead)
				}	
			},
			attached() {
				const that = this;
				uni.getSystemInfo({
					success: res => {
						if (res.platform == 'windows') { //pc端小程序
							app.globalData.biasTop_88 = 0;
							that.offTop = 0;
						} else if (app.globalData.biasTop_88 != 0) {
							that.offTop = app.globalData.biasTop_88;
							var info = uni.getMenuButtonBoundingClientRect();
							that.navWidth = info.width;
						} else {
							var info = uni.getMenuButtonBoundingClientRect();
							that.navWidth = info.width;
							// console.log(that.navWidth)
							const query = uni.createSelectorQuery().in(this);
							this.$nextTick(res => {
								query.select('.head').boundingClientRect((rect) => {
									that.offTop = -(rect.height - info.height) / 2 - (that
										.navTop - that.menuTop);
									app.globalData.biasTop_88 = that.offTop; //88rpx高度的偏差
								}).exec();
							})
						}
					}
				})
			},

			handlePageShow() {
				// 页面被展示
				var that = this;
				if (that.platForm != 'web') {
					let info = uni.getMenuButtonBoundingClientRect();
					that.menuTop = info.top;
				}
				that.grayscale = app.globalData.appConfig.sitePageGray == '1' || app.globalData.appConfig
					.sitePageGray == '2' ? 'grayscale' : '';

				//当前城市
				uni.getStorage({
					key: 'cityInfo',
					success(res) {
						console.log(typeof res.data);
						that.cityInfoClone = typeof res.data == "string" ? JSON.parse(res.data) : res.data
						// 获取定位
						try {
							var value = uni.getStorageSync('currlocation');
							if (value) {
								that.lng = value.split(',')[0];
								that.lat = value.split(',')[1];
								// tt.getDataList();
							} else {
								that.getCurrLocation(); //获取当前定位
							}
						} catch (e) {
							console.log('CatchClause', e);
							console.log('CatchClause', e);
							that.getCurrLocation(); //获取当前定位
						}
					},

					fail(res) {
						console.log(res);
						// 获取 当前 定位的城市
						try {
							var value = uni.getStorageSync('currlocation');
							if (value) {
								that.lng = value.split(',')[0];
								that.lat = value.split(',')[1];
								app.globalData.cityInfo = {};
								app.getCityInfo(value.split(',')[0], value.split(',')[1]);
							} else {
								that.getCurrLocation();
							}
						} catch (e) {
							console.log('CatchClause', e);
							console.log('CatchClause', e);
							that.getCurrLocation();
						}
						var interVal = setInterval(function() {
							uni.getStorage({
								key: 'cityInfo',

								success(res) {
									that.cityInfoClone = res.data;
									clearInterval(interVal);
								}
							});
						}, 1000);
					}
				});
				var pageArr = getCurrentPages();
				if (pageArr.length == 1) {
					//只有1个页面
					//返回大首页
					this.homeBackClone = true
				}

				var cityInterval = setInterval(function() {
					if (app.globalData.cityNum) {
						that.cityNum = app.globalData.cityNum
						clearInterval(cityInterval);
					}
				}, 1000);
				var interval = setInterval(function() {
					if (app.globalData.appConfig && app.globalData.appConfig.cfg_user_index) {
						that.navList = [{
								url: '/pages/index/index',
								title: '返回首页',
								icon: 'home_icon.png',
								type: '3'
							},
							{
								url: app.addUrlParam(app.globalData.appConfig
									.cfg_user_index + '/message.html'),
								title: '消息',
								icon: 'msg_icon.png',
								type: '2',
								msg: true
							},
							{
								url: app.addUrlParam(app.globalData.appConfig
									.cfg_user_index),
								title: '个人中心',
								icon: 'member_icon.png',
								type: '2'
							}, // {
							//   'url':app.globalData.masterDomain + '/shop/cart.html?appTitle',
							//   'title':'购物车',
							//   'icon':'cart_icon.png',
							//   'type':'2'
							// },
							{
								url: app.addUrlParam(app.globalData.appConfig
									.cfg_user_index + '/collection.html?module=info'),
								title: '我的收藏',
								icon: 'star_icon.png',
								type: '2'
							},
							{
								url: app.addUrlParam(app.globalData.appConfig
									.cfg_user_index + '/history?module=info'),
								title: '我的足迹',
								icon: 'clock_icon.png',
								type: '2'
							}
						];
						clearInterval(interval);
					}
				}, 1000);

				// 页面被隐藏
				if (getMessageInterval) {
					clearInterval(getMessageInterval);
				}

				//获取未读消息
				// var userid = app.globalData.userid;
				// if (userid != null && userid != 'undefined') {
				that.getMessage();
				if (that.needMessage) {
					console.log('测试1')
					this.timerHead = setInterval(function() {
						that.getMessage();
					}, 5000);
				}
				// }

				if(Boolean(app.globalData.userid)){
					that.pageShowCheck(5)
				}


			},
			wexin() { //微信平台处理
				const navInfo = uni.getMenuButtonBoundingClientRect(); //胶囊处理
				this.navLeft = `${navInfo.left - 10}px`
				this.showClone = true;
				this.platForm = 'mp-weixin';
			},
			toutiao() { //抖音平台处理
				this.navLeft = '100%';
				this.platForm = 'mp-toutiao';
			},
			handlePageResize(size) {},

			backIndex() {
				const myEventDetail = {}; // detail对象，提供给事件监听函数
				this.$emit('backIndex', {
					detail: myEventDetail
				});
			},

			homeBackFun() {
				uni.reLaunch({
					url: '/pages/index/index'
				});
			},

			// 点击返回按钮
			goback() {
				var tt = this;
				app.backFn(`/pages/index/index`);
			},

			// 显示菜单
			showMenu(e) {
				var tt = this;
				tt.headMenuShow = true
			},

			// 隐藏菜单
			hideMenu(e) {
				var tt = this;
				tt.headMenuShow = false
			},

			// 跳转链接
			goLink(e) {
				var currentTarget = e.currentTarget;
				var url = currentTarget.dataset.url;
				if (!url) {
					return false;
				}
				if (currentTarget.dataset.type == 1) {
					uni.navigateTo({
						url: app.addUrlParam(url)
					});
				} else if (currentTarget.dataset.type == 2) {
					uni.navigateTo({
						url: '/pages/redirect/index?url=' + url.replace('?', 'huoniaowh').replace(/&/g,
							'huoniaolj').replace(/=/g, 'huoniaodh')
					});
				} else if (currentTarget.dataset.type == 3) {
					uni.reLaunch({
						url: app.addUrlParam(url)
					});
				} else {
					uni.reLaunch({
						url: '/pages/index/index'
					});
				}
			},

			// 获取模块底部按钮
			getMessage() {
				// console.log('头部信息获取—1')
				var tt = this;
				var access_token = uni.getStorageSync('access_token');
				if (!access_token) {
					tt.msgNum = 0
					return;
				}
				var dataPrarm = 'service=member&action=message&type=tongji&im=1';
				var urlData = app.encodeUrl(dataPrarm);
				this.$ajax.post({
					url: 'include/ajax.php?' + urlData,
				}).then(res => {
					var data = res.data;
					if (data.state == 100) {
						tt.msgNum = data.info.pageInfo.total > 99 ? '99+' : data.info.pageInfo
							.total
					} else if (data.info == '用户信息验证失败') {
						//如果1秒后还没有登录信息，则自动退出并打开登录页面
						setTimeout(function() {
							//如果access_token不存在，直接清空storeage数据并跳转到登录页面
							if (!uni.getStorageSync('access_token')) {
								//退出
								uni.showToast({
									title: '账号状态异常，请重新登录！',
									icon: 'none',
									duration: 2000
								});
								uni.removeStorage({
									key: 'userid'
								});
								uni.removeStorage({
									key: 'access_token'
								});
								uni.removeStorage({
									key: 'refresh_token'
								});
								uni.removeStorage({
									key: 'token_expired'
								});
								app.globalData.userid = null;
								app.globalData.access_token = null;
								app.globalData.refresh_token = null;
								app.globalData.token_expired = null;
								app.tologin('/pages/goback');

								//如果access_token存在，并且接口还提示『用户信息验证失败』，可能是账号在多个设备上进行了登录，此时需要用refresh_token验证下状态，如果可用，则更新本地token，如果不可用，则清空storeage数据并回到首页
							} else {
								var res = refreshToken.unit(uni.getStorageSync('refresh_token'),
									app.globalData.masterDomain,
									function(datas) {
										if (datas.state == 100) {
											console.log('更新成功');
											console.log(datas.info);
											var access_token = datas.info.access_token;
											var refresh_token = datas.info.refresh_token;

											// console.log('更新token：' + new Date());
											// console.log(datas.info);

											uni.setStorage({
												key: 'access_token',
												data: access_token
											});
											uni.setStorage({
												key: 'refresh_token',
												data: refresh_token
											});
											var token_expired = Date.parse(new Date()) / 1000 +
												7200 - 20; //两个小时有效期，保险起见，用1小时59分钟40秒
											uni.setStorage({
												key: 'token_expired',
												data: token_expired
											});
											app.globalData.access_token = access_token;
											app.globalData.refresh_token = refresh_token;
											app.globalData.token_expired = token_expired;
										} else {
											//清除缓存数据
											uni.removeStorage({
												key: 'userid'
											});
											uni.removeStorage({
												key: 'access_token'
											});
											uni.removeStorage({
												key: 'refresh_token'
											});
											uni.removeStorage({
												key: 'token_expired'
											});
											app.globalData.userid = null;
											app.globalData.access_token = null;
											app.globalData.refresh_token = null;
											app.globalData.token_expired = null;

											//跳转到登录页面
											// var isLoginning = wx.getStorage('isLoginning');
											// if(!isLoginning){
											//     wx.setStorage({
											//         key:"isLoginning",
											//         data:1
											//     })

											var url = encodeURIComponent(app.globalData
												.masterDomain + '/logout.html?redirect=' +
												app.globalData.masterDomain + '/login.html'
											);
											uni.redirectTo({
												url: '/pages/redirect/index?url=' +
													encodeURIComponent(url),
												success: res => {
													console.log('跳转');
												}
											});
											// }
										}
									});
							}
						}, 1000);
					}
				})
			},

			// 获取当前定位
			getCurrLocation() {
				var tt = this;
				app.globalData.locationFn({
					// type: 'gcj02',
					type: tt.platForm == 'web' ? 'wgs84' : 'gcj02', //平台切换：H5没有gcj02，需要配置SKD
					success(res) {
						//成功获取定位
						const lat = res.latitude || res.lat;
						const lng = res.longitude || res.lng;
						tt.lng = res.longitude || res.lng;
						tt.lat = res.latitude || res.lat;
						app.globalData.lnglat = lat + ',' + lng
						uni.setStorage({
							key: 'currlocation',
							data: lng + ',' + lat
						});
						app.globalData.cityInfo = {};
						app.getCityInfo(lng, lat);
					},
					fail(res) {
						console.log(tt.platForm, 666);
						// 获取当前城市分站
						try {
							var value = uni.getStorageSync('cityInfo');
							if (value) {
								app.globalData.cityInfo = value;
							} else {
								app.getdefaultCity();
							}
						} catch (e) {
							console.log('CatchClause', e);
							console.log('CatchClause', e);
							// Do something when catch error
							app.getdefaultCity();
						}
					}
				})
			},

			// 扫码
			scanQr() {
				var tt = this;
				// 允许从相机和相册扫码
				uni.scanCode({
					success(res) {
						var url = res.result;
						let match2 =
							/^((http|https):\/\/)?(([A-Za-z0-9]+-[A-Za-z0-9]+|[A-Za-z0-9]+)\.)+([A-Za-z]+)[/\?\:]?.*$/;
						if (match2.test(url)) {
							uni.navigateTo({
								url: '/pages/redirect/index?url=' + url.replace('?', 'huoniaowh').replace(
									/&/g, 'huoniaolj').replace(/=/g, 'huoniaodh')
							});
						} else if (res.scanType == 'EAN_13') {
							uni.navigateTo({
								url: '/pages/redirect/index?url=' +
									encodeURIComponent(app.globalData.masterDomain +
										'/include/ajax.php?service=shop&action=barcodeSearch&type=redirect&code=' +
										url)
							});
						} else {
							uni.showModal({
								title: '扫码结果',
								content: res.result,
								showCancel: false
							});
						}
					}
				});
			},

			// 跳转搜索页
			toSearchPage(e) {
				var tt = this;
				var url = e.currentTarget.dataset.url;
				if (!url) {
					var url = app.globalData.masterDomain;
					var cityid = 0;
					var value = uni.getStorageSync('cityInfo');
					if (value) {
						value = value;
						cityid = value.cityid;
					}
					uni.navigateTo({
						url: '/pages/redirect/index?url=' + encodeURIComponent(url + '/siteSearch.html?cityid=' +
							cityid)
					});
				} else {
					tt.goLink(e);
				}
			},

			catchTouchMove() {
				console.log('占位：函数 catchTouchMove 未声明');
			},

			// 返回上一页
			gobackFn(){
				const that = this;
				if(that.click_disabled) return false;
				that.click_disabled = true;
				let canNavBack = getCurrentPages();
				that.$nextTick(() => {
					that.click_disabled = false;
				})

				if(app.globalData.platForm == 'web'){
					var touch_mo = function(e) {
						e.preventDefault();
					};
					document.body.style.overflow = ''; //出现滚动条
					document.removeEventListener("touchmove", touch_mo, false);
				}

				// h5端 显示在小程序里
				if(app.globalData.platForm == 'web' && app.globalData.webMini){
					jWeixin.miniProgram.navigateBack(); //直接返回上一次
					return false
				}

				if(app.globalData.platForm != 'web' || app.globalData.appBoolean || (canNavBack && canNavBack.length > 1)){
					app.backFn(this.module?`/pages/packages/${this.module}/index/index`:`/pages/index/index`,app.globalData.masterDomain);
				}else{
					window.history.go(-1);
				}

				
			},

			pageShowCheck(timeOut){ // timeOut => 单位是分钟 一段时间过后 修改定时器  interval请求时间间隔 单位是秒
				const that = this;
				let next_timeOut = timeOut;
				let interval = 5
				switch(timeOut){
					case 5: 
						next_timeOut = 10,
						interval = 10;
						break;
					case 10: 
						next_timeOut = 20,
						interval = 20;
						break;
					case 20: 
						next_timeOut = 30,
						interval = 30;
						break;
					case 30: 
						next_timeOut = 60,
						interval = 60;
						break;
					case 60: 
						next_timeOut = 0,
						interval = 0;
						break;
				}
				setTimeout(() => {
					clearInterval(that.timerHead)
					if(timeOut && interval){
						that.timerHead = setInterval(this.getMessage,interval * 1000)
					}
					if(next_timeOut){
						that.pageShowCheck(next_timeOut)
					}
				},timeOut * 60 * 1000);
			}

		},
		watch: {
			cityInfo: {
				handler(newVal, oldVal) {
					this.cityInfoClone = newVal;
				},

				immediate: true
			},

			homeBack: {
				handler(newVal, oldVal) {
					this.homeBackClone = newVal;
				},

				immediate: true
			},
			
			pageHide(newVal, oldVal) {
				if (newVal) {
					clearInterval(this.timerHead);
				} else if (Boolean(app.globalData.userid)) {
					this.timerHead = setInterval(res => {
						this.getMessage();
					}, 5000)
				}
			}
		}
	};
</script>
<style>
	@import './public_header.css';
</style>